package com.triones.api.controller.web.interlace;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.triones.api.entity.BankCardTypeDO;
import com.triones.api.entity.interlace.dto.InterlaceCardBinsDO;
import com.triones.api.entity.interlace.vo.InterlaceCardBinsVO;
import com.triones.api.service.interlace.InterlaceCardBinsService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

/**
 * card bins管理
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/interlace/cardBins")
public class CardBinsController extends BaseController {

    private final InterlaceCardBinsService interlaceCardBinsService;

    /**
     * 列表（分页）
     */
    @SaCheckPermission("system:cardBins:pageList")
    @GetMapping("/pageList")
    public TableDataInfo<InterlaceCardBinsVO> list(InterlaceCardBinsDO dto, PageQuery pageQuery) {
        return interlaceCardBinsService.selectPageList(dto, pageQuery);
    }

    /**
     * 详细
     */
    @SaCheckPermission("system:cardBins:query")
    @GetMapping(value = "/{id}")
    public R<InterlaceCardBinsVO> getDetail(@PathVariable Long id) {
        return R.ok(interlaceCardBinsService.getDetail(id));
    }

    /**
     * 匹配bin信息
     */
    @SaCheckPermission("system:cardBins:match")
    @PostMapping
    public R<Void> match(@NotBlank(message = "bin 编号不能为空") String bin) {
        return toAjax(interlaceCardBinsService.matchCardBin(bin));
    }

    /**
     * 修改
     */
    @SaCheckPermission("system:cardBins:edit")
    @PutMapping
    public R<Void> edit(@Validated @RequestBody InterlaceCardBinsDO dto) {
        return toAjax(interlaceCardBinsService.edit(dto));
    }

    /**
     * 状态修改
     */
    @PutMapping("/changeStatus")
    public R<Void> changeShowStatus(@RequestBody InterlaceCardBinsDO dto) {
        return toAjax(interlaceCardBinsService.changeShowStatus(dto));
    }

    /**
     * 删除卡种
     */
    @SaCheckPermission("system:cardBins:remove")
    @DeleteMapping("/{id}")
    public R<Void> remove(@PathVariable Long id) {
        return toAjax(interlaceCardBinsService.remove(id));
    }
}
